{% extends "base.html" %}

{% block meta %}
    <meta name="menu-tag" content="23"/>
{% end block %}

{% block main %}
<div class="container">
    <ol class="breadcrumb">
        <li class="active">容器服务信息</li>
    </ol>

    <!-- 查询结果开始 -->
    <table class="table table-striped table-bordered" >
        <caption>
            <h4><strong></strong></h4>
        </caption>
        <thead>
            <tr>
                <th>服务名称</th>
                <th>创建时间</th>
                <th>运行主机</th>
                <th>主机IP</th>
                <th>状态</th>
                <th>关闭</th>
            </tr>
        </thead>
        <tbody id="tbl">
            {% import datetime %}
            {% for service in services %}
            <tr>
                <td>{{ service['servicename'] }}</td>
                <td>{{ datetime.datetime.strptime(service['createdtime'][0:16],'%Y-%m-%dT%H:%M') }}</td>
                <td>{{ service['hostname'] }}</td>
                <td>{{ service['ip'] }}</td>
                <td>{{ service['state'] }}</td>
                <td>
                    <button class="btn btn-sm btn-danger" type="button" onclick="shutdown();">关闭容器服务</button>
                </td>
            </tr>
            {% end %}
        </tbody>
    </table>
</div>
{% end block %}


{% block script %}
<script type="text/javascript">
    function shutdown(){
        tr = event.target.parentElement.parentElement;
        serviceName = tr.firstElementChild.innerHTML;
        bootbox.confirm('确实要关闭容器服务【' + serviceName + '】吗?', function(choice){
            if (choice){
                $.post('/docker_services?servicename=' + serviceName, function(result){
                    if (result){
                        bootbox.alert("容器服务关闭成功");
                        document.getElementById('tbl').removeChild(tr);
                    } else{
                        bootbox.alert("容器服务关闭失败");
                    }
                })
            }
        });
    }
</script>
{% end block %}
